
#include "testObject.h"

CPPUNIT_TEST_SUITE_REGISTRATION (testObject);

void testObject :: setUp (void){
	obj = new object();
}

void testObject :: tearDown (void) {
	delete obj;
}

void testObject :: testObjectSetAndGetValue (void)
{
	obj->set("name", "object");
	CPPUNIT_ASSERT_EQUAL (obj->get("name"), (string)"object");
}

void testObject :: testAppendToAnotherObject (void)
{
	obj->set("name", "baseObject");

	object *obj2 = new object();
	obj2->set("name", "appendObject");
	obj->append(obj2);

	CPPUNIT_ASSERT_EQUAL (obj->current()->get("name"), (string)"appendObject");

	delete obj2;
}

void testObject :: testAppendMoreObjectsToAnotherObject (void)
{

	obj->set("name", "baseObject");

	object *obj1 = new object();
	obj1->set("name", "appendObject 1");
	obj->append(obj1);
	object *obj2 = new object();
	obj2->set("name", "appendObject 2");
	obj->append(obj2);
	object *obj3 = new object();
	obj3->set("name", "appendObject 3");
	obj->append(obj3);

	CPPUNIT_ASSERT_EQUAL (obj->get("name"), (string)"baseObject");
	CPPUNIT_ASSERT_EQUAL (obj->current()->get("name"), (string)"appendObject 1");
	obj->next();
	CPPUNIT_ASSERT_EQUAL (obj->current()->get("name"), (string)"appendObject 2");
	obj->next();
	CPPUNIT_ASSERT_EQUAL (obj->current()->get("name"), (string)"appendObject 3");
	delete obj1;
	delete obj2;
	delete obj3;
}

void testObject :: testOverrideObjectWithGetAndSetInTestFixtureObject (void) {
	testFixtureObject *obj1 = new testFixtureObject();
	obj1->set("value","test value");
	CPPUNIT_ASSERT_EQUAL ( (string)"test value", obj1->get("value"));
	delete obj1;

}

void testObject :: testObjectWithGetAndSetTheValuesWithOneObject(void) {
	array valueMap;
	valueMap["value1"] = "a";
	obj->setValues(valueMap);
	array newValues = obj->getValues();
	CPPUNIT_ASSERT_EQUAL ( (string)"a", newValues["value1"].get());
}

void testObject :: testObjectWithGetAndSetTheValues(void) {
	array valueMap;
	valueMap["value1"] = "a";
	valueMap["value2"] = "b";
	valueMap["value3"] = "c";
	valueMap["value4"] = "d";
	valueMap["value5"] = "e";
	obj->setValues(valueMap);
	array newValues = obj->getValues();
	CPPUNIT_ASSERT_EQUAL ( (string)"a", newValues["value1"].get());
	CPPUNIT_ASSERT_EQUAL ( (string)"b", newValues["value2"].get());
	CPPUNIT_ASSERT_EQUAL ( (string)"c", newValues["value3"].get());
	CPPUNIT_ASSERT_EQUAL ( (string)"d", newValues["value4"].get());
	CPPUNIT_ASSERT_EQUAL ( (string)"e", newValues["value5"].get());
}

void testObject :: testOverrideObjectWithGetAndSetTheValues(void) {
	testFixtureObject *obj1 = new testFixtureObject();
	array valueMap;
	valueMap["value1"] = "a";
	valueMap["value2"] = "b";
	valueMap["value3"] = "c";
	valueMap["value4"] = "d";
	valueMap["value5"] = "e";
	obj1->setValues(valueMap);
	array newValues = obj1->getValues();
	CPPUNIT_ASSERT_EQUAL ( (string)"a", newValues["value1"].get());
	CPPUNIT_ASSERT_EQUAL ( (string)"b", newValues["value2"].get());
	CPPUNIT_ASSERT_EQUAL ( (string)"c", newValues["value3"].get());
	CPPUNIT_ASSERT_EQUAL ( (string)"d", newValues["value4"].get());
	CPPUNIT_ASSERT_EQUAL ( (string)"e", newValues["value5"].get());
	delete obj1;
}

void testObject :: testObjectHasNextWithNoItem(void) {
	CPPUNIT_ASSERT_EQUAL ( false, obj->hasNext());
}

void testObject :: testObjectHasNextWithOneItem(void) {
	object *obj1 = new object();
	obj->append(obj1);
	CPPUNIT_ASSERT_EQUAL ( true , obj->hasNext());
	CPPUNIT_ASSERT_EQUAL ( false , obj1->hasNext());
	delete obj1;
}

void testObject :: testObjectEraseCommentFromContent() {
	std::string configuration = obj->loadFromFile("res/configuration_object.conf");
	obj->eraseComments(&configuration);
	CPPUNIT_ASSERT_EQUAL ( -1 , (int)configuration.find("#") );
}

void testObject :: testPutConfigurationContentIntoObject() {
	std::string configuration = obj->loadFromFile("res/configuration_object.conf");
	obj->putConfigurationContentIntoObject(configuration);
	CPPUNIT_ASSERT_EQUAL ( (string)"value1", obj->configuration["test1"]);
	CPPUNIT_ASSERT_EQUAL ( (string)"1", obj->configuration["testcomment"]);
}

void testObject :: testObjectSetConfiguration() {
	obj->setConfiguration("object");
	CPPUNIT_ASSERT_EQUAL ( (string)"value1", obj->configuration["test1"]);
	CPPUNIT_ASSERT_EQUAL ( (string)"1", obj->configuration["testcomment"]);
}

void testObject :: testIsFileWithNoExistsFile() {
	CPPUNIT_ASSERT_EQUAL (
		obj->isFile("res/configuration_object_noexists.conf"),
		false
	);
}

void testObject :: testIsFileWithExistsFile() {
	CPPUNIT_ASSERT_EQUAL (
		obj->isFile("res/configuration_object.conf"),
		true
	);
}

void testObject :: testLoadFromFileReturnsCorrectText() {
	CPPUNIT_ASSERT_EQUAL (
		(string)"Text for unittest to loadFromFile Methode",
		obj->loadFromFile("res/testContentFile")
	);
}

void testObject :: testDeleteFileWithExistsFileReturnsTrue() {
	obj->saveToFile(
		"res/testFileToDelete",
		"Content To Test DeleteFile"
	);

	CPPUNIT_ASSERT_EQUAL (
		true,
		obj->deleteFile("res/testFileToDelete")
	);

	CPPUNIT_ASSERT_EQUAL (
		false,
		obj->isFile("res/testFileToDelete")
	);

}

void testObject :: testDeleteFileWithNoExistsFileReturnsFalse() {
	CPPUNIT_ASSERT_EQUAL (
		false,
		obj->deleteFile("res/testFileToDeleteNotExistsOnDisk")
	);
}

void testObject :: testSaveToFileAndLoadCorrectText() {

	bool result = obj->saveToFile(
		"res/tempFileToCheckSaveToFileInUnitTest",
		"Here are the content for the test case"
	);

	CPPUNIT_ASSERT_EQUAL (
		true,
		result
	);
	CPPUNIT_ASSERT_EQUAL (
		(string)"Here are the content for the test case",
		obj->loadFromFile("res/tempFileToCheckSaveToFileInUnitTest")
	);
}

void testObject :: testSaveToFileWithNotExistsDirectoryReturnsFalse() {
	bool result = obj->saveToFile(
		"noExistsDirectoryToSave/tempFileToCheckSaveToFileInUnitTest",
		"Text"
	);

	CPPUNIT_ASSERT_EQUAL (
		false,
		result
	);
}




